<?php 
// Provide a simple display when entering or viewing comments
if (($section == "comments") || ($section == "view_comments")) { 
?>
<div id="comment-preview">
<h2><?php echo $row_courses['jiu_course_id']; ?> Course Project Description <?php if (($id != "default") && ($row_user['userLevel'] <= "2")) echo " (Version ".$row_cpd['vid'].")"; ?></h2>
<h3>In the course project, students will...</h3>
<?php echo $row_cpd['project_desc1']; ?>
</div>

<?php } // END if (($section == "comments") || ($section == "view_comments"))

// Display in table format when viewing the entire proposal
else 
{
	if ($totalRows_cpd > 0) {
		$query_cpd_latest = "SELECT * FROM course_project WHERE cid='$cid' ORDER BY vid DESC LIMIT 1"; 
		$cpd_latest = mysql_query($query_cpd_latest, $connection) or die(mysql_error());
		$row_cpd_latest = mysql_fetch_assoc($cpd_latest);
		$totalRows_cpd_latest = mysql_num_rows($cpd_latest);
		
		if ($id == "default") $query_cpd_comments = sprintf("SELECT * FROM comments WHERE cid='%s' AND tableName='%s' AND rid='%s'", $cid, "course_project", $row_cpd_latest['id']);
		else $query_cpd_comments = sprintf("SELECT * FROM comments WHERE cid='%s' AND tableName='%s' AND rid='%s'", $cid, "course_project", $row_cpd['id']);
		$cpd_comments = mysql_query($query_cpd_comments, $connection) or die(mysql_error());
		$row_cpd_comments = mysql_fetch_assoc($cpd_comments);
		$totalRows_cpd_comments = mysql_num_rows($cpd_comments);

if ($id != "default") {
	if (($row_cpd_latest['vid'] == $row_cpd['vid']) && ($totalRows_cpd_comments > 0)) echo "<div class='error_msg'>Changes are needed to the course project description.</div>";
	if (($totalRows_cpd_comments > 0) && ($modal_window == "false")) echo "<div class='info'><a href='#comments'>Click here</a> to view the comments from the Instructional Designer.</div>";
	}
?>
<a name="cpd"></a><h2>Course Project Description <?php if (($id != "default") && ($row_user['userLevel'] <= "2")) echo " (Version ".$row_cpd['vid'].")"; ?></h2>
<table class="dataTable">
  <tr>
  	<th colspan="5">In the course project, students will...</th>
  </tr>
  <?php if (($section != "proposal_reveiw") && ($id == "default") && ($modal_window != "true") && ($row_user['userLevel'] <= "2")) { ?>
  <tr>
  	<td colspan="5">
    <span class="icon"><img src="images/page_edit.png" align="absmiddle" border="0"></span><a id="modal_window_link" href="index.php?section=cpd&action=edit&go=<?php echo $go; ?>&amp;view=proposal_detail&cid=<?php echo $cid; ?>&vid=<?php echo $row_cpd['vid']; ?>&id=<?php echo $row_cpd['id']."&amp;modal_window=true"; ?>" title="Edit the Course Description">Edit</a>
    </td>
  </tr>
  <?php } ?>
  <tr>
    <td colspan="5"><?php echo $row_cpd['project_desc1']; ?></td>
  </tr>
  <?php if (($modal_window == "false") && ($id == "default")) { ?>
  <tr>
    <th width="20%"><?php if (($section != "proposal_reveiw") && ($id == "default") && ($modal_window != "true")) { ?>ID / Reviewer Comments?<?php } else echo "&nbsp;"; ?></th>
    <th width="20%"><?php if (($section != "proposal_reveiw") && ($id == "default") && ($modal_window != "true")) { ?>Changes Needed?<?php } else echo "&nbsp;"; ?></th>
    <th width="20%"><?php if (($section == "view_proposal") && ($row_user['userLevel'] <= "2")) { ?>Latest Version<?php } else echo "&nbsp;"; ?></th>
    <th width="20%"><?php if (($section == "view_proposal") && ($row_user['userLevel'] <= "2")) { ?>Other Versions<?php } else echo "&nbsp;"; ?></th>
    <th><?php if ($section == "proposal_reveiw") { ?>Make Changes?<?php } else echo "&nbsp;"; ?></th>
  </tr>
  <tr>
    <td class="data">
    <?php if (($section != "proposal_reveiw") && ($id == "default") && ($modal_window != "true")) { 
	echo view_comments('course_project','view_comments',$cid,$row_cpd['id'],'proposal_detail',$totalRows_cpd_comments,'modal'); 
	if ($row_user['userLevel'] <= "2") echo "<div class='stacked'><span class='icon'><img src='images/comment_add.png' align='absmiddle' border='0'></span><a id='modal_window_link' href='index.php?section=comments&action=add&cid=".$cid."&dbTable=course_project&id=".$row_cpd['id']."&amp;modal_window=true'>Add Comment</a></div>";  
	} ?>
    </td>
    <td class="data">
	<?php if (($section != "proposal_reveiw") && ($id == "default") && ($modal_window != "true")) { 
	if ($row_cpd_comments['changes'] == "Y") echo "<span class='icon'><img src='images/error.png' align='absmiddle' border='0'></span>Yes - <a id='modal_window_link' href='index.php?section=cpd&amp;action=add&amp;go=".$go."&amp;view=proposal_detail&amp;cid=".$cid."&id=".$row_cpd['id']."&amp;modal_window=true' title='View ID Comments About Changes'>Make Changes</a>"; else echo "<span class='icon'><img src='images/tick.png' align='absmiddle' border='0'></span>No"; 
	} ?>
    </td>
    <td class="data"><?php if (($section == "view_proposal") && ($row_user['userLevel'] <= "2"))  echo $row_cpd['vid']; ?></td>
    <td class="data">
    <?php
	if (($section == "view_proposal") && ($row_user['userLevel'] <= "2")) echo previous_versions("course_project",$cid,$row_cd['vid'],$modal_window,$section,$action); else echo "&nbsp;";
	?>
    </td>
        <td class="data"><?php if ($section == "proposal_reveiw") { ?><a href="index.php?section=cpd&amp;action=edit&amp;go=review&amp;view=<?php echo $view; ?>&amp;cid=<?php echo $cid; ?>&vid=<?php echo $row_cpd['vid']; ?>&amp;id=<?php echo $row_cpd['id']; ?>">Yes</a><?php } ?></td>
    
  </tr>
  <?php } ?>
</table>
<?php echo top_link($section,$modal_window); 
}
else { echo "<a name=\"cpd\"></a><h2>Course Project Description</h2><div class='error_msg'>A Course Project Description has not been entered. "; if ($row_user['userLevel'] == "3") { if ($totalRows_cpd > 0) echo "<a href='index.php?section=cpd&action=add&cid=".$cid."'>Add one?</a>"; else echo "Please <a href='index.php?section=cd&action=add&cid=".$cid."'>add the Course Description</a> first."; } echo "</div>"; }
?>
<?php if (($id != "default") && ($totalRows_comments > 0) && ($section != "comments") && ($section != "view_comments")) { ?>
<a name="comments"></a><h2>ID Comments</h2>
<table class="dataTable">
<tr>
	<th width="10%" nowrap="nowrap">Instructional Designer</th>
    <th>Comments</th>
    <th width="13%">Changes Needed?</th>
    <th width="13%"></th>
</tr>
<?php do { ?>
<tr>
	<td width="5%" nowrap="nowrap"><p><?php echo $row_id['firstName']." ".$row_id['lastName']; ?><p></td>
    <td class="data"><?php echo $row_comments['comment']; ?></td>
    <td class="data"><?php if ($row_cpd_latest['vid'] == $row_cpd['vid']) { if ($row_comments['changes'] == "Y") echo "<span class='icon'><img src='images/error.png' align='absmiddle' border='0'></span>Yes"; else echo "<span class='icon'><img src='images/tick.png' align='absmiddle' border='0'></span>No"; }  else echo "Version out of date."  ?>
    <td class="data">
	<?php 
	if (($row_cpd_latest['vid'] == $row_cpd['vid']) && ($row_comments['changes'] == "Y") && ($row_user['userLevel'] = "3")) echo "<a href='index.php?section=cpd&action=edit&go=detail&cid=".$cid."&id=".$row_comments['rid']."'>Make Changes</a>"; else echo "&nbsp;" ?>
    </td>
</tr>
<?php if ($color == $color1) { $color = $color2; } else { $color = $color1; } ?>
<?php } while ($row_comments = mysql_fetch_assoc($comments)); ?>
</table>
<?php } 
} ?>